package com.ruoyi.jiajia.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JiajiaTimePriceConfig;
import com.ruoyi.system.service.IJiajiaTimePriceConfigService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 时间价格配置Controller
 * 
 * @author 郑鑫
 * @date 2024-04-23
 */
@Controller
@RequestMapping("jiajia/timePriceConfig")
public class JiajiaTimePriceConfigController extends BaseController
{
    private String prefix = "jiajia/timePriceConfig";

    @Autowired
    private IJiajiaTimePriceConfigService jiajiaTimePriceConfigService;

    @RequiresPermissions("jiajia:timePriceConfig:view")
    @GetMapping()
    public String timePriceConfig()
    {
        return prefix + "/timePriceConfig";
    }

    /**
     * 查询时间价格配置列表
     */
    @RequiresPermissions("jiajia:timePriceConfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaTimePriceConfig jiajiaTimePriceConfig)
    {
        startPage();
        List<JiajiaTimePriceConfig> list = jiajiaTimePriceConfigService.selectJiajiaTimePriceConfigList(jiajiaTimePriceConfig);
        return getDataTable(list);
    }

    /**
     * 导出时间价格配置列表
     */
    @RequiresPermissions("jiajia:timePriceConfig:export")
    @Log(title = "时间价格配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaTimePriceConfig jiajiaTimePriceConfig)
    {
        List<JiajiaTimePriceConfig> list = jiajiaTimePriceConfigService.selectJiajiaTimePriceConfigList(jiajiaTimePriceConfig);
        ExcelUtil<JiajiaTimePriceConfig> util = new ExcelUtil<JiajiaTimePriceConfig>(JiajiaTimePriceConfig.class);
        return util.exportExcel(list, "时间价格配置数据");
    }

    /**
     * 新增时间价格配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存时间价格配置
     */
    @RequiresPermissions("jiajia:timePriceConfig:add")
    @Log(title = "时间价格配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaTimePriceConfig jiajiaTimePriceConfig)
    {
        return toAjax(jiajiaTimePriceConfigService.insertJiajiaTimePriceConfig(jiajiaTimePriceConfig));
    }

    /**
     * 修改时间价格配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaTimePriceConfig jiajiaTimePriceConfig = jiajiaTimePriceConfigService.selectJiajiaTimePriceConfigById(id);
        mmap.put("jiajiaTimePriceConfig", jiajiaTimePriceConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存时间价格配置
     */
    @RequiresPermissions("jiajia:timePriceConfig:edit")
    @Log(title = "时间价格配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaTimePriceConfig jiajiaTimePriceConfig)
    {
        return toAjax(jiajiaTimePriceConfigService.updateJiajiaTimePriceConfig(jiajiaTimePriceConfig));
    }

    /**
     * 删除时间价格配置
     */
    @RequiresPermissions("jiajia:timePriceConfig:remove")
    @Log(title = "时间价格配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaTimePriceConfigService.deleteJiajiaTimePriceConfigByIds(ids));
    }
}
